#!/bin/bash

# Analysis Params
if   [ $# -eq 0 ]
then
        exit -1
elif [ $# -eq 1 ]
then
        HOST="127.0.0.1"
else
        HOST=$1
        shift
fi

# If run on localhost, try to get community strings
COMM_STR="public"
if   [ ! -z "$HOST" ]
then
    if   [ "$HOST" == "localhost" -o "$HOST" == "127.0.0.1" ]
    then
        # Search community string
        if [ -f "/etc/snmp/snmpd.conf" ]
        then
            SNMP_CONF="/etc/snmp/snmpd.conf"
        elif [ -f "/etc/snmpd.conf" ]
        then
            SNMP_CONF="/etc/snmpd.conf"
        fi

        COMM_STR=`cat $SNMP_CONF | grep "community" | grep "127.0.0.1" | awk '{print $2; exit 0}'`

        if [ -z "$COMM_STR" ]
        then
            COMM_STR="public"
        fi
    fi
fi

while [ $# -gt 0 ] ; do
        echo $HOST $1
	snmpwalk -mALL -v1 -Os -c$COMM_STR $HOST $1
	shift
done
exit 0

